#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc.h"
#include "IOConfig.h"

u8 VT6110_bufferR[50];
u8 VT6110_bufferG[50];
u8 VT6110_bufferB[50];


u8 VT6110_REG_R0[18]; //length+cmd+data
u8 VT6110_REG_R1[18];
u8 VT6110_REG_R2[18];
u8 VT6110_REG_R3[4];

u8 VT6110_REG_G0[18]; //length+cmd+data
u8 VT6110_REG_G1[18];
u8 VT6110_REG_G2[18];
u8 VT6110_REG_G3[4];

u8 VT6110_REG_B0[18]; //length+cmd+data
u8 VT6110_REG_B1[18];
u8 VT6110_REG_B2[18];
u8 VT6110_REG_B3[4];


void VT6110_Write_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
    SSD2828_W_Array(SigMode,channel,buffer,2);                               

    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写寄存器状态  ：ok  
}
void VT6110_Read_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u16 tmp;
    buffer[1]=0x03;
    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,buffer[2]); //return package size                                
    SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer[0] = 0x01;
    buffer[1] = buffer[3];                        
    SSD2828_W_Array(SigMode,channel,buffer,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
    for(i=0;i<buffer[2]-1;i++)
    {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[4+i]=tmp>>8;
        buffer[5+i]=tmp;
        delay_ms(5);
        i++;
    }
		buffer[0]=0x70;	
		buffer[1]=0x02;
    //SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		SSD2828_W_Reg(SigMode,channel,0xB7,0x034b);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的 寄存器数据  ：ok 
}


void VT6110_Write_Gamma_Video(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
    u8 i,j,k=0,temp;
	  u8 m = 0x00;
					
		if((buffer[3]&0xFF)==0x00)
		{
			for( i = 0;i<16;i++)   //8个绑点                                                                                  
			{VT6110_bufferR[i]=buffer[i+5];}	    
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_bufferR[i+16]=buffer[i+21];}
			for( i = 0;i<16;i++)   //8个绑点	                                                                                  
			{VT6110_bufferR[i+32]=buffer[i+37];}
			for( i = 0;i<2;i++)   //1个绑点	                                                                                  
			{VT6110_bufferR[i+48]=buffer[i+53];}
	  }	
		else if((buffer[3]&0xFF)==0x42)
		{
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferG[i]=buffer[i+5];} 		 
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferG[i+16]=buffer[i+21];} 		 
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferG[i+32]=buffer[i+37];}	 
			for( i = 0;i<2;i++)   //1个绑点
			{VT6110_bufferG[i+48]=buffer[i+53];}
		}
		else if((buffer[3]&0xFF)==0x81)
		{
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferB[i]=buffer[i+5];} 		 
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferB[i+16]=buffer[i+21];}		 
			for( i = 0;i<16;i++)   //8个绑点
			{VT6110_bufferB[i+32]=buffer[i+37];}		 
			for( i = 0;i<2;i++)   //1个绑点
			{VT6110_bufferB[i+48]=buffer[i+53];}
	  }
		if(SigMode==Video_Mode)
		{
			SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		}
		else
		{
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		}
	    delay_ms(5);	
		

		buffer1[0] = 0x03;        
		buffer1[1] = 0xF0;
		buffer1[2] = 0xAA;
		buffer1[3] = 0x13;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		 
		buffer1[0] = 0x02;        
		buffer1[1] = 0xC4;
		buffer1[2] = 0x01; 
		SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
		buffer1[1] = 0xBF;
		buffer1[2] = buffer[4]; //gamma_group_sel
		SSD2828_W_Array(SigMode,channel,buffer1,0);		        
		delay_ms(5);
		
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB0); //GAMMA RED GROUP1
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferR[i]);	
		}				 
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB1); //GAMMA RED GROUP2
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferR[i+16]);	
		}									 
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB2); //GAMMA RED GROUP3
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferR[i+32]);	
		}			 
		SSD2828_W_Reg(SigMode,channel,0xBC,3); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB3); //GAMMA RED GROUP4
		for(i=0; i<2; i++)
		{     
			SSD2828_W_Data(SigMode,channel,VT6110_bufferR[i+48]);	
		}
		delay_ms(5); 
//--------------------------------------------------------------
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB4); //GAMMA GREEN GROUP1
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferG[i]);	
		}		
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB5); //GAMMA GREEN GROUP2
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferG[i+16]);	
		}	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);
		SSD2828_W_Data(SigMode,channel,0xB6); //GAMMA GREEN GROUP3
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferG[i+32]);
		}
		SSD2828_W_Reg(SigMode,channel,0xBC,3);
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB7); //GAMMA GREEN GROUP3
		for(i=0; i<2; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferG[i+48]);
		}
//----------------------------------------------------------------------		
		delay_ms(5); 	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB8); //GAMMA BLUE GROUP1
		for(i=0; i<16; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferB[i]);	
		}		
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xB9); //GAMMA BLUE GROUP2
		for(i=0; i<16; i++)
		{
			 SSD2828_W_Data(SigMode,channel,VT6110_bufferB[i+16]);	
		}	
		SSD2828_W_Reg(SigMode,channel,0xBC,17); 			
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xBA); //GAMMA BLUE GROUP3
		for(i=0; i<16; i++)
		{
			 SSD2828_W_Data(SigMode,channel,VT6110_bufferB[i+32]);	
		}			 
		SSD2828_W_Reg(SigMode,channel,0xBC,3); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);	
		SSD2828_W_Data(SigMode,channel,0xBB); //GAMMA BLUE GROUP4
		for(i=0; i<2; i++)
		{
			SSD2828_W_Data(SigMode,channel,VT6110_bufferB[i+48]);	
		}
		delay_ms(5); 			
		buffer1[2] = 0x02;				
		buffer1[1] = 0xC4;
		buffer1[2] = 0x00;    
		SSD2828_W_Array(SigMode,channel,buffer1,0);		

		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);				
		delay_ms(5); 
		buffer[0]=0x70;	//VT6110
		buffer[1]=0x08;		
		buffer[4] = Uart_Error_None;
		buffer[5] = 0;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //返回 写寄存器状态  ：ok   
}


void VT6110_Write_Gamma_Command(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[7];
		u8 i,j,k=0,temp;
		u8 m = 0x00;
					
		if((buffer[3]&0xFF)==0x00)
		{
			VT6110_REG_R0[0]=17;
			VT6110_REG_R0[1]=0xB0;
			for( i = 0;i<16;i++)   //8个绑点                                                                                  
			{VT6110_REG_R0[i+2]=buffer[i+5];}	

			VT6110_REG_R1[0]=17;
			VT6110_REG_R1[1]=0xB1;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_R1[i+2]=buffer[i+21];}
				
			VT6110_REG_R2[0]=17;
			VT6110_REG_R2[1]=0xB2;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_R2[i+2]=buffer[i+37];}
			
			VT6110_REG_R3[0]=3;
			VT6110_REG_R3[1]=0xB3;
			for( i = 0;i<2;i++)   //1个绑点                                                                                 
			{VT6110_REG_R3[i+2]=buffer[i+53];}	
		}	
		else if((buffer[3]&0xFF)==0x42)
		{
			VT6110_REG_G0[0]=17;
			VT6110_REG_G0[1]=0xB4;
			for( i = 0;i<16;i++)   //8个绑点                                                                                  
			{VT6110_REG_G0[i+2]=buffer[i+5];}	

			VT6110_REG_G1[0]=17;
			VT6110_REG_G1[1]=0xB5;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_G1[i+2]=buffer[i+21];}

			VT6110_REG_G2[0]=17;
			VT6110_REG_G2[1]=0xB6;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_G2[i+2]=buffer[i+37];}
			
			VT6110_REG_G3[0]=3;
			VT6110_REG_G3[1]=0xB7;
			for( i = 0;i<2;i++)   //1个绑点                                                                                 
			{VT6110_REG_G3[i+2]=buffer[i+53];}	
		}
		else if((buffer[3]&0xFF)==0x81)
		{
			VT6110_REG_B0[0]=17;
			VT6110_REG_B0[1]=0xB8;
			for( i = 0;i<16;i++)   //8个绑点                                                                                  
			{VT6110_REG_B0[i+2]=buffer[i+5];}	

			VT6110_REG_B1[0]=17;
			VT6110_REG_B1[1]=0xB9;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_B1[i+2]=buffer[i+21];}

			VT6110_REG_B2[0]=17;
			VT6110_REG_B2[1]=0xBA;
			for( i = 0;i<16;i++)   //8个绑点                                                                                 
			{VT6110_REG_B2[i+2]=buffer[i+37];}
			
			VT6110_REG_B3[0]=3;
			VT6110_REG_B3[1]=0xBB;
			for( i = 0;i<2;i++)   //1个绑点                                                                                 
			{VT6110_REG_B3[i+2]=buffer[i+53];}	
		}
		if(SigMode==Video_Mode)
		{
			SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		}
		else
		{
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		}
	    delay_ms(5);	
		

		buffer1[0] = 0x03;        
		buffer1[1] = 0xF0;
		buffer1[2] = 0xAA;
		buffer1[3] = 0x13;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		 
		buffer1[0] = 0x02;        
		buffer1[1] = 0xC4;
		buffer1[2] = 0x01; 
		SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
		buffer1[1] = 0xBF;
		buffer1[2] = buffer[4]; //gamma_group_sel
		SSD2828_W_Array(SigMode,channel,buffer1,0);		        
		delay_ms(5);

		//GAMMA RED GROUP1
		SSD2828_W_Array(SigMode,channel,VT6110_REG_R0,0);
		//GAMMA RED GROUP2
		SSD2828_W_Array(SigMode,channel,VT6110_REG_R1,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_R2,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_R3,0);
		delay_ms(5);
//---------------------------------------------------------------------		
		//GAMMA RED GROUP1
		SSD2828_W_Array(SigMode,channel,VT6110_REG_G0,0);
		//GAMMA RED GROUP2
		SSD2828_W_Array(SigMode,channel,VT6110_REG_G1,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_G2,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_G3,0);	
		delay_ms(5);
//----------------------------------------------------------------------		
		//GAMMA RED GROUP1
		SSD2828_W_Array(SigMode,channel,VT6110_REG_B0,0);
		//GAMMA RED GROUP2
		SSD2828_W_Array(SigMode,channel,VT6110_REG_B1,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_B2,0);
	  //GAMMA RED GROUP3
		SSD2828_W_Array(SigMode,channel,VT6110_REG_B3,0);
	//---------------------------------------------------------		
		delay_ms(5); 			
		buffer1[2] = 0x02;				
		buffer1[1] = 0xC4;
		buffer1[2] = 0x00;    
		SSD2828_W_Array(SigMode,channel,buffer1,0);		

		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);				
		delay_ms(5); 
		buffer[0]=0x70;	//VT6110
		buffer[1]=0x08;		
		buffer[4] = Uart_Error_None;
		buffer[5] = 0;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //返回 写寄存器状态  ：ok   
}



void VT6110_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	if(SigMode==Video_Mode)
	{
		VT6110_Write_Gamma_Video(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
	}
	else if(SigMode==CMD_Mode)
	{
		VT6110_Write_Gamma_Command(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
	}
}

void VT6110_Write_255G_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
    u8 i,j,k=0,temp;
	  u8 m = 0x00;
					
		if((buffer[3]&0xFF)==0x00)
		{
			for( i = 0;i<2;i++)   //255绑点	                                                                                  
			{VT6110_bufferR[i+48]=buffer[i+53];}
	  }	
		else if((buffer[3]&0xFF)==0x42)
		{ 
			for( i = 0;i<2;i++)   //255绑点
			{VT6110_bufferG[i+48]=buffer[i+53];}
		}
		else if((buffer[3]&0xFF)==0x81)
		{	 
			for( i = 0;i<2;i++)   //255绑点
			{VT6110_bufferB[i+48]=buffer[i+53];}
	  }
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		delay_ms(2);		

		buffer1[0] = 0x03;        
    buffer1[1] = 0xF0;
    buffer1[2] = 0xAA;
	  buffer1[3] = 0x13;
    SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  buffer1[0] = 0x02;        
    buffer1[1] = 0xC4;
    buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
		buffer1[1] = 0xBF;
		buffer1[2] = buffer[4]; //gamma_group_sel
		SSD2828_W_Array(SigMode,channel,buffer1,0);		        
		delay_ms(5);
		
//------------------red/green/blue---------------------	 
		SSD2828_W_Reg(SigMode,channel,0xBC,3); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);
		 
		SSD2828_W_Data(SigMode,channel,0xB3); //GAMMA RED GROUP4
		for(i=0; i<25; i++)
		{SSD2828_W_Data(SigMode,channel,VT6110_bufferR[i+48]);}
	
		SSD2828_W_Data(SigMode,channel,0xB7); //GAMMA GREEN GROUP3
		for(i=0; i<2; i++)
		{SSD2828_W_Data(SigMode,channel,VT6110_bufferG[i+48]);}
		 
		SSD2828_W_Data(SigMode,channel,0xBB); //GAMMA BLUE GROUP4
		for(i=0; i<2; i++)
		{SSD2828_W_Data(SigMode,channel,VT6110_bufferB[i+48]);}
		delay_ms(2); 				
    buffer1[2] = 0x02;				
    buffer1[1] = 0xC4;
    buffer1[2] = 0x00;    
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);		
		delay_ms(2); 				
    buffer[0]=0x70;	//VT6110
    buffer[1]=0x08;		
    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //返回 写寄存器状态  ：ok   
}

void VT6110_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
			u8 buffer1[7];
			u16 tmp;
			u8 i,j;
	
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	    delay_ms(5);	
			buffer1[0] = 0x03;        
			buffer1[1] = 0xF0;
			buffer1[2] = 0xAA;
			buffer1[3] = 0x13;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		 
			buffer1[0] = 0x02;        
			buffer1[1] = 0xC4;
			buffer1[2] = 0x01;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
			buffer1[1] = 0xBF;
			buffer1[2] = buffer[4]; //gamma_group_sel
			SSD2828_W_Array(SigMode,channel,buffer1,0);		        
			buffer1[1] = 0xC4;
			buffer1[2] = 0x00;    
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
	
	
	    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
		

		Generate_MIPI_Read(pdev,SigMode,channel,0xB0 ,16, VT6110_bufferR);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB1 ,16, VT6110_bufferR+16);	delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB2 ,16, VT6110_bufferR+16+16);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB3 ,2, VT6110_bufferR+16+16+16);delay_ms(5);

		Generate_MIPI_Read(pdev,SigMode,channel,0xB4 ,16, VT6110_bufferG);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB5 ,16, VT6110_bufferG+16);	delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB6 ,16, VT6110_bufferG+16+16);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB7 ,2, VT6110_bufferG+16+16+16);delay_ms(5);

		Generate_MIPI_Read(pdev,SigMode,channel,0xB8 ,16, VT6110_bufferB);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xB9 ,16, VT6110_bufferB+16);	delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xBA ,16, VT6110_bufferB+16+16);delay_ms(5);
		Generate_MIPI_Read(pdev,SigMode,channel,0xBB ,2, VT6110_bufferB+16+16+16);delay_ms(5);

		
		if((buffer[3]&0xff)==0x00)       //GAMMA RED
		{     
			for(j=0;j<50;j++)
			{
				buffer[4+j]=VT6110_bufferR[j];	  	
			}               			   
		}
		else if((buffer[3]&0xff)==0x42)  //GAMMA GREEN
		{	
	    for(j=0;j<50;j++)
			{
				buffer[4+j]=VT6110_bufferG[j];	  		
			}              
		}
		else if((buffer[3]&0xff)==0x81)   //GAMMA BLUE
		{		
			for(j=0;j<50;j++)
			{
				buffer[4+j]=VT6110_bufferB[j];								
			}        
		} 
					
    buffer[0]=0x70;	//VT6110
    buffer[1]=0x09;
		
		delay_ms(15);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);          //返回 读取的 Gamma数据  ：ok  		

    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
}



void VT6110_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[10];
	  u8 mtp_flag;
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15); 
    buffer1[0] = 0x01;
    buffer1[1] = 0x28;                    
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(10); 
	  buffer1[0] = 0x03;
    buffer1[1] = 0xF0; 
	  buffer1[2] = 0xAA;
	  buffer1[3] = 0x12;
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(1); 
	  buffer1[0] = 0x02;
    buffer1[1] = 0xCA; 
	  buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(1); 		
		buffer1[0] = 0x04;
		buffer1[1] = 0xE6;	
		if(buffer[3]==0x0D)  //otp Gamma
		{	 
			buffer1[2] = 0x00;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x80; 
		}
		else if(buffer[3]==0x0E)  //otp ALL
		{
			buffer1[2] = 0x9F;  
			buffer1[3] = 0x1F;
			buffer1[4] = 0x80;  
		}
		else if(buffer[3]==0x0F)  //otp PAGE 0
		{
			buffer1[2] = 0xB1;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1B)  //otp PAGE 1
		{	 
			buffer1[2] = 0x02;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1C)  //otp PAGE 2
		{
			buffer1[2] = 0x04;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1D)  //otp PAGE 5
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x02;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1A)  //otp PAGE 4
		{		 
			buffer1[2] = 0x00;  
			buffer1[3] = 0x01;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1E)  //otp PAGE 7
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x08;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1F)  //otp PAGE 8
		{
		//	buffer1[2] = 0x00;  
		//	buffer1[3] = 0x08;
		//	buffer1[4] = 0x00;  
		}		
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(5); 	 
		buffer1[0] = 0x04;
		buffer1[1] = 0xE7;
		buffer1[2] = 0x88;    
		buffer1[3] = 0x55;    
		buffer1[4] = 0x11;    
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(3000); 	
		buffer1[0] = 0x04;
		buffer1[1] = 0xE6;
		buffer1[2] = 0x00;  
		buffer1[3] = 0x00;
		buffer1[4] = 0x00;  
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(10); 
		buffer1[0] = 0x02;
		buffer1[1] = 0xCA;
		buffer1[2] = 0x02;  //
		SSD2828_W_Array(SigMode,channel,buffer1,0);     		 
		delay_ms(10);
//		buffer[1] = 0x0E;
		buffer[2] = 0x02;
		buffer[3] = Uart_Error_None;   //返回 OTP Gamma数据  ：OK
		buffer[4] = 0;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);         
}


void ProcessForIc70( USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	switch(buffer[1])
	{
		case 0x01:                                      //写寄存器
			VT6110_Write_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;	
		case 0x02:                                      //读寄存器
			VT6110_Read_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
		case 0x03:                                      //读寄存器
			VT6110_Write_255G_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;				
		case 0x08:                                      //写Gamma数据    
			VT6110_Write_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x09:                                      //读Gamma数据
			VT6110_Read_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break; 
		case 0x0D://OTP Gamma
			VT6110_Gamma_OTP_Start(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);  break;	
		default:	break;	
	}	
}


